#!/bin/bash

source /home/seekcy/.bash_profile

dir="$( cd "$( dirname "$0" )" && pwd )"

case "$1" in 
    start)
        nohup java -Dloader.path=$dir/config -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006 wwyt-server.jar > /dev/null 2>&1 &
        #java -Dloader.path=$dir/config -jar -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5006 wwyt-server.jar
        ;;
    stop)
        ps aux | grep wwyt-server.jar | grep -v grep | awk '{print $2}' | xargs kill
        sleep 5
        pid=`ps aux | grep wwyt-server.jar | grep -v grep | awk '{print $2}'`
        if [ $pid ]; then
          kill -9 $pid
        fi
        ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        echo "=== restart ==="
        ;;

    *)
        $0 stop
        sleep 2
        $0 start
        ;;
esac
exit 0
